package com.hunttown.mes.service;

import com.hunttown.mes.dao.AnalysisMysqlQueryDao;
import com.hunttown.common.domain.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * MYSQL条件组装
 * created by wangjunfu on 2019-01-29 16:13:45
 */
@Service
public class AnalysisMysqlQueryService {

    private final static Logger logger = LoggerFactory.getLogger(AnalysisMysqlQueryService.class);

    private final AnalysisMysqlQueryDao analysisMysqlQueryDao;

    @Autowired
    public AnalysisMysqlQueryService(AnalysisMysqlQueryDao analysisMysqlQueryDao) {
        this.analysisMysqlQueryDao = analysisMysqlQueryDao;
    }

    //按日期创建一张表，并且将符合条件的(create_time)数据插入到该表中（不区分哪个企业的）
    public void backupTableByDate(Query query) {
        //检查：dbName
        if (!query.containsKey("dbName")) {
            return;
        }

        //检查：toTable
        if (!query.containsKey("toTable")) {
            return;
        }

        //检查：fromTable
        if (!query.containsKey("fromTable")) {
            return;
        }

        //检查：createTime
        if (!query.containsKey("createTime")) {
            return;
        }

        analysisMysqlQueryDao.backupTableByDate(query);
    }

    //删除符合条件的(create_time)数据（不区分哪个企业的）
    public void deleteInformationByDate(Query query) {
        //检查：dbName
        if (!query.containsKey("dbName")) {
            return;
        }

        //检查：fromTable
        if (!query.containsKey("fromTable")) {
            return;
        }

        //检查：createTime
        if (!query.containsKey("createTime")) {
            return;
        }

        analysisMysqlQueryDao.deleteInformationByDate(query);
    }
}